package com.jinhua.huaojbackendserviceclient.service;


import cn.hutool.json.JSONUtil;
import com.jinhua.huaojbackendmodel.model.entity.JudgeCase;
import com.jinhua.huaojbackendmodel.model.entity.JudgeConfig;
import com.jinhua.huaojbackendmodel.model.entity.Question;
import com.jinhua.huaojbackendmodel.model.entity.QuestionSubmit;
import com.jinhua.huaojbackendmodel.model.vo.QuestionView;
import org.springframework.beans.BeanUtils;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
* @author 20289
* @description 针对表【question(题目表)】的数据库操作Service
* @createDate 2024-09-28 13:40:09
*/
@FeignClient(name = "huaoj-backend-question-service", path = "/huaoj/question/inner")
public interface QuestionFeignClient {

    @GetMapping("/get/id")
    Question getQuestionById(@RequestParam("questionId") long questionId);

    @GetMapping("/submit/get/id")
    QuestionSubmit getQuestionSubmitById(@RequestParam("questionSubmitId") long questionSubmitId);

    @PostMapping("/submit/update")
    boolean updateQuestionSubmitById(@RequestBody QuestionSubmit questionSubmit);


    /**
     * 获取未脱敏题目页面
     * @param question
     * @return
     */
    default QuestionView getQuestionView(Question question){
        QuestionView questionView = new QuestionView();
        BeanUtils.copyProperties(question, questionView);
        // todo 使用QuestionView的 objtoView

        String tagsJSON = question.getTags();
        String judgeConfigJSON = question.getJudgeConfig();
        String judgeCaseJSON = question.getJudgeCase();


        List<String> tags = JSONUtil.toList(tagsJSON, String.class);
        List<JudgeCase> judgeCaseList = JSONUtil.toList(judgeCaseJSON, JudgeCase.class);
        JudgeConfig judgeConfig = JSONUtil.toBean(judgeConfigJSON, JudgeConfig.class);

        questionView.setTags(tags);
        questionView.setJudgeConfig(judgeConfig);
        questionView.setJudgeCase(judgeCaseList);


        return questionView;
    }



}
